﻿using Expression.Blend.SampleData.SampleDataSource;
using System;
using System.Linq;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
using Tareas.ServiceReference;
using System.Collections.Generic;
using Windows.UI.ApplicationSettings;

namespace Tareas
{
    partial class App
    {
        // TODO: Create a data model appropriate for your problem domain to replace the sample data
        private static SampleDataSource _sampleData;

        public App()
        {
            InitializeComponent();
        }

        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            ShowCollection();
            Window.Current.Activate();
        }

        public static void ShowCollection()
        {
            var page = new CollectionPage();
            if (_sampleData == null) _sampleData = new SampleDataSource(page.BaseUri);
            //page.Items = _sampleData.GroupedCollections.Select((obj) => (Object)obj);
            Window.Current.Content = page;
        }

        public static void ShowSplit(IGroupInfo collection)
        {
            var page = new SplitPage();
            if (_sampleData == null) _sampleData = new SampleDataSource(page.BaseUri);
            if (collection == null) collection = _sampleData.GroupedCollections.First();
            page.Items = collection;
            page.Context = collection.Key;
            Window.Current.Content = page;
        }

        public static void ShowTaskDetails(Project p)
        {
            var page = new ProjectDetails();
            page.Project = p;
            Window.Current.Content = page;
        }

        protected override void OnSearchActivated(Windows.ApplicationModel.Activation.SearchActivatedEventArgs args)
        {
            var searchResultsPage = new Tareas.SearchResultsPage();
            searchResultsPage.Activate(args);
        }

        protected override void OnSharingTargetActivated(Windows.ApplicationModel.Activation.ShareTargetActivatedEventArgs args)
        {
            var shareTargetPage = new Tareas.SharingPage();
            shareTargetPage.Activate(args);
        }

        protected override void OnFilePickerActivated(Windows.ApplicationModel.Activation.FilePickerActivatedEventArgs args)
        {
            var itemPickerPage = new Tareas.AppToAppPickingPage();
            itemPickerPage.Activate(args);
        }
    }
}
